package com.xpec.c4.net.codec;

import java.nio.ByteBuffer;

import net.sf.cindy.Buffer;
import net.sf.cindy.Packet;
import net.sf.cindy.PacketEncoder;
import net.sf.cindy.Session;
import net.sf.cindy.buffer.BufferFactory;
import net.sf.cindy.packet.DefaultPacket;
import net.sf.cindy.util.Charset;

/**
 * 
 * 
 * @author Bany
 *
 * @since 2009-4-28 下午11:04:51
 *
 */

public class StringEncoder  implements PacketEncoder{

	@Override
	public Packet encode(Session session, Object obj) throws Exception {
		ByteBuffer bytebuff=Charset.UTF8.encode((String)obj);
		Buffer buffer = BufferFactory.allocate(bytebuff.capacity());
		buffer.put(bytebuff);
		buffer.position(0);
		
        return new DefaultPacket(buffer);
	}

}
